<html>
<head><meta charset="utf-8"><title>Is this correct? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html">Is this correct?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220704051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220704051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220704051">(Dec 22 2020 at 15:57)</a>:</h4>
<p>Hi, </p>
<p>Ignoring the use of macros, I was wondering if the following is a correct understanding of the repo.</p>
<p><strong>CrateGraph structure</strong></p>
<p><strong>Creation</strong> : Created manually usually from cargo information.   </p>
<p><strong>Usage</strong>: Shows the dependencies between crates and metadata such as crate edition, crate config flags, the root file for the crate (<a href="http://lib.rs/main.rs">lib.rs/main.rs</a>) usually</p>
<hr>
<p><strong>CrateDefMap structure</strong> </p>
<p><strong> Creation</strong>: This is used quite a lot in r-a and to be created it needs to go over the whole source file. </p>
<p><strong>Usage</strong>: Shows the definitions with a crate. For a given crate, this will essentially be the modules. There is also an <code>extern prelude</code> which I believe is for connecting external crates together. This is different to the <code>prelude</code> which is also a field in this structure. </p>
<hr>
<h2>Def Collector structure</h2>
<p><strong>Creation</strong>: This is created along with the CrateDefMap creation.  </p>
<p><strong>Usage</strong>: In order to populate the crate def map, we need to collect the definitions. This is what this data structure does with the <code>collect_defs</code> method.</p>
<hr>
<p><strong>collect_defs method</strong></p>
<p><strong>Usage</strong> : As mentioned above, this is used to create a DefCollector and collect definitions.</p>
<p><strong>Notes:</strong> This method will first fetch the crate graph, and get the dependencies for the crate you are trying to fetch definitions for. For each dependency, you will create a CrateDefMap. This means that this is a recursive call. Luckily, the CrateGraph prevents cyclic dependencies between crates.</p>
<p>After collecting the CrateDefMap for the dependency, the dependency name and it’s root moduleID is added to the CrateDefMap of the crate in question. It is added to the <code>extern prelude</code> field. This is how this crate will have access  to definitions in an external crate.</p>
<p>Of interest, at the end of the method, a DefCollector structure is instantiated with the def_map of the crate in question. This DefMap now has the DefMap of all of its dependencies indirectly.</p>
<p>def_collector.collect() is then called.</p>
<hr>
<h2>DefCollector::collect method</h2>
<p><strong>usage :</strong> As mentioned above, the main job of the DefCollector is to collect Definitions in a crate. We could not do this if we did not collect the definitions of it’s dependencies first. We have done this, so now we have all of the information needed.  </p>
<p><strong>Note:</strong>  The first thing we do is we create an ItemTree from the root_file_id. In most cases the root_file_id will be (<a href="http://lib.rs/main.rs">lib.rs/main.rs</a>).  </p>
<p>Now since a crate is just a bunch of modules, we give the ItemTree to a ModCollector data structure, which collects all of the definitions within the Module using the item tree for that root file. If the root module declares another module ie <code>mod foo</code>, then we also recursively collect that module in this procedure  </p>
<p>We then need to do import resolution, ie the use statements. We do not do Name Resolution here it seems.</p>
<hr>
<p><strong>ModCollector::collect method</strong>  </p>
<p><strong>usage:</strong> Collects all definitions within a module.  </p>
<p><strong>Note:</strong>  This holds a mut ref to the def collector, because whenever we see a use statement here, we simply add it to the list of unresolved imports and resolve those after. See DefCollector::collect where I mention import resolution</p>



<a name="220704287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220704287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220704287">(Dec 22 2020 at 15:59)</a>:</h4>
<p>not sure who to ping, maybe <span class="user-mention" data-user-id="133169">@matklad</span>  ?</p>



<a name="220705908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220705908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220705908">(Dec 22 2020 at 16:12)</a>:</h4>
<p>If any of this is correct, I'm wondering also:</p>
<ul>
<li>what is the purpose of the ItemTree?</li>
<li>where the part is that does variable resolution is?</li>
</ul>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">k</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"> </span><span class="c1">// a is not defined</span>
</code></pre></div>
<p>The part which gives the above error for example. Or are definitions in the CrateDefMap not necessarily resolved lexically yet?</p>



<a name="220706777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220706777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220706777">(Dec 22 2020 at 16:21)</a>:</h4>
<p>This is correct in broad strokes, yeah <span class="user-mention" data-user-id="369769">@kev</span></p>



<a name="220706840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220706840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220706840">(Dec 22 2020 at 16:21)</a>:</h4>
<p>Btw, if you intend to pursue this investigation furhter,   it woudl be really helpful if you can write this all down and submit as a pull reqeust to the architercture.md document :-)</p>



<a name="220706942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220706942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220706942">(Dec 22 2020 at 16:22)</a>:</h4>
<p>Couple of clarification:</p>
<p><code>DefCollector</code> is only a temporary, ephemeral data structure, and its sole goal is producing the <code>CrateDefMap</code></p>



<a name="220706954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220706954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220706954">(Dec 22 2020 at 16:23)</a>:</h4>
<p>After <code>DefMap</code> is ready, the collector is gone.</p>



<a name="220707252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707252">(Dec 22 2020 at 16:24)</a>:</h4>
<p>Important point about <code>CrateGraph</code> is that it allows several logical crates share the same source file. Ie, you can have <code>CrateId(0)</code> and <code>CrateId(1)</code> both point to <code>src/lib.rs</code>, with the difference that <code>0</code> is <code>--cfg=test</code>, and <code>1</code> is not</p>



<a name="220707489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707489">(Dec 22 2020 at 16:25)</a>:</h4>
<p>Variable resolution happens here: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_def/src/body/scope.rs">https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_def/src/body/scope.rs</a></p>



<a name="220707600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707600">(Dec 22 2020 at 16:26)</a>:</h4>
<p>TYpe-dependent resolution <code>x.meth()</code> happens during the rest of the type inference, over here: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_ty/src/infer/expr.rs#L835-L840">https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_ty/src/infer/expr.rs#L835-L840</a></p>



<a name="220707654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707654">(Dec 22 2020 at 16:26)</a>:</h4>
<p>As for the <code>ItemTree</code>, in the broad strokes its sole purpose is performance optimization</p>



<a name="220707746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707746">(Dec 22 2020 at 16:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220706840">said</a>:</p>
<blockquote>
<p>Btw, if you intend to pursue this investigation furhter,   it woudl be really helpful if you can write this all down and submit as a pull reqeust to the architercture.md document :-)</p>
</blockquote>
<p>Yep!</p>



<a name="220707859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707859">(Dec 22 2020 at 16:28)</a>:</h4>
<p>It would be totally possible to construct <code>CrateDefMap</code> directly from <code>SyntaxNode</code>s, bypassing the item tree. </p>
<p>We, however, insert an <code>ItemTree</code> as a mediator there. <code>ItemTree</code> is build <em>per-file</em> (so, it doesn't know about modules, cfg flags or crates). It's core property is that, if you edit code inside a function's body, the item tree for the corresponing file stays the same.</p>



<a name="220707879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707879">(Dec 22 2020 at 16:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220707252">said</a>:</p>
<blockquote>
<p>Important point about <code>CrateGraph</code> is that it allows several logical crates share the same source file. Ie, you can have <code>CrateId(0)</code> and <code>CrateId(1)</code> both point to <code>src/lib.rs</code>, with the difference that <code>0</code> is <code>--cfg=test</code>, and <code>1</code> is not</p>
</blockquote>
<p>Ah right, I noticed that from the tests, where the same FileID was used multiple times</p>



<a name="220707924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220707924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220707924">(Dec 22 2020 at 16:29)</a>:</h4>
<p>That means that, when you edit inside functions (so, most of the time), we can avoid re-computing name resolution, because name resolution looks only at the ItemTrees, and not at the raw text/sytnax trees</p>



<a name="220708145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708145">(Dec 22 2020 at 16:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220707489">said</a>:</p>
<blockquote>
<p>Variable resolution happens here: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_def/src/body/scope.rs">https://github.com/rust-analyzer/rust-analyzer/blob/b28322eed6b977eb566444e8edbb229f4f610cd6/crates/hir_def/src/body/scope.rs</a></p>
</blockquote>
<p>If I have an item tree, can I be sure that variables have been resolved?</p>



<a name="220708304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708304">(Dec 22 2020 at 16:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220707859">said</a>:</p>
<blockquote>
<p>It would be totally possible to construct <code>CrateDefMap</code> directly from <code>SyntaxNode</code>s, bypassing the item tree. </p>
<p>We, however, insert an <code>ItemTree</code> as a mediator there. <code>ItemTree</code> is build <em>per-file</em> (so, it doesn't know about modules, cfg flags or crates). It's core property is that, if you edit code inside a function's body, the item tree for the corresponing file stays the same.</p>
</blockquote>
<p>Oh this makes sense to me, as you pass the ItemTree to the ModuleCollector which then iterates the items and resolves the module declarations</p>



<a name="220708637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708637">(Dec 22 2020 at 16:36)</a>:</h4>
<p>No names are resolved in the item tree</p>



<a name="220708707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708707">(Dec 22 2020 at 16:36)</a>:</h4>
<p>It's a simplified view of the syntax tree</p>



<a name="220708830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708830">(Dec 22 2020 at 16:37)</a>:</h4>
<blockquote>
<p>If I have an item tree, can I be sure that variables have been resolved?</p>
</blockquote>
<p>The opposite actually: item tree simply doesn't contain information about local variables. This is why it doesn't change when you add new local variable!</p>



<a name="220708916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708916">(Dec 22 2020 at 16:38)</a>:</h4>
<p>that's the whole trick behind bening incremental -- you try to actively ignore and avoid knowing more than you stricktly need :)</p>



<a name="220708947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220708947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220708947">(Dec 22 2020 at 16:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220708637">said</a>:</p>
<blockquote>
<p>No names are resolved in the item tree</p>
</blockquote>
<p>Not sure why I keep erroring on this fact :(</p>



<a name="220709159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709159">(Dec 22 2020 at 16:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220708830">said</a>:</p>
<blockquote>
<blockquote>
<p>If I have an item tree, can I be sure that variables have been resolved?</p>
</blockquote>
<p>The opposite actually: item tree simply doesn't contain information about local variables. This is why it doesn't change when you add new local variable!</p>
</blockquote>
<p>So If I have</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">mod</span> <span class="nn">foo</span><span class="p">;</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">bar</span><span class="p">;</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">K</span><span class="w"> </span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"hello"</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">hello</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>

<span class="kd">let</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="k">u64</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The ItemTree would only contain the information about the module declarations, the hello function, and the constant K ?</p>



<a name="220709236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709236">(Dec 22 2020 at 16:41)</a>:</h4>
<p>yeah, and it only knows about item signatures, not bodies</p>



<a name="220709523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709523">(Dec 22 2020 at 16:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220709236">said</a>:</p>
<blockquote>
<p>yeah, and it only knows about item signatures, not bodies</p>
</blockquote>
<p>Oh so it only know that there is a constant K of type &amp;Str.</p>
<p>If I were to connect what you and matklad are saying, when you say "it only knows about",  do you mean it has a stable ID to the definition, but it does not know the contents?</p>



<a name="220709761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709761">(Dec 22 2020 at 16:45)</a>:</h4>
<p>So even if </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">     </span><span class="k">const</span><span class="w"> </span><span class="n">K</span><span class="w"> </span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"hello"</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>changes to </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">     </span><span class="k">const</span><span class="w"> </span><span class="n">K</span><span class="w"> </span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"world"</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>This is fine since, what was being stored was:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Item</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="n">constant</span><span class="w"> </span>: <span class="nc">K</span><span class="w"></span>
<span class="w">  </span><span class="k">type</span> : <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">body_id</span><span class="w"> </span>: <span class="mi">2</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>And <code>body_id : 2</code> does not change between compilations</p>



<a name="220709831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709831">(Dec 22 2020 at 16:46)</a>:</h4>
<p>yes, see: <a href="https://rust-analyzer.github.io/rust-analyzer/hir_def/item_tree/struct.Const.html">https://rust-analyzer.github.io/rust-analyzer/hir_def/item_tree/struct.Const.html</a></p>



<a name="220709954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220709954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220709954">(Dec 22 2020 at 16:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/220709831">said</a>:</p>
<blockquote>
<p>yes, see: <a href="https://rust-analyzer.github.io/rust-analyzer/hir_def/item_tree/struct.Const.html">https://rust-analyzer.github.io/rust-analyzer/hir_def/item_tree/struct.Const.html</a></p>
</blockquote>
<p>Oh thanks, it points to an AST_ID so if I were to move const K down the page, then it would recompile since it is a different AST Node number?</p>



<a name="220710067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220710067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220710067">(Dec 22 2020 at 16:48)</a>:</h4>
<p>yeah, if you move it past another item</p>



<a name="220710284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220710284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220710284">(Dec 22 2020 at 16:50)</a>:</h4>
<p>Oh interesting, that the span changing does not cause it to recompile</p>



<a name="220710377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/220710377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#220710377">(Dec 22 2020 at 16:51)</a>:</h4>
<p>I guess since span is only really needed for error reporting, it is something you can put in a side table or recompute from the absolute width of each node starting from the top...</p>
<p>Thanks for correcting by the way :) matklad and Jonas</p>



<a name="221148967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221148967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221148967">(Dec 29 2020 at 17:05)</a>:</h4>
<p>So <code>ItemTreeData</code> has an <code>exprs</code> field that's not used, what is it supposed to do? Can I remove it?</p>



<a name="221149396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221149396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221149396">(Dec 29 2020 at 17:10)</a>:</h4>
<p>For now, yeah</p>



<a name="221149416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221149416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221149416">(Dec 29 2020 at 17:10)</a>:</h4>
<p>I think it was supposed to be used for array lengths</p>



<a name="221149428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221149428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221149428">(Dec 29 2020 at 17:11)</a>:</h4>
<p>Are you looking into ItemTree memory usage?</p>



<a name="221149742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221149742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221149742">(Dec 29 2020 at 17:15)</a>:</h4>
<p>I tried to, but couldn't find much. I'm not even sure where the memory goes. The query shows 315MB on RA, but if I duplicate all of the <code>ItemTree</code> members (the method from <a href="https://rust-analyzer.github.io/blog/2020/12/04/measuring-memory-usage-in-rust.html#amdahls-estimator">https://rust-analyzer.github.io/blog/2020/12/04/measuring-memory-usage-in-rust.html#amdahls-estimator</a>), it only grows to 445 MB. 430 MB when duplicating only <code>ItemTreeData</code>.</p>



<a name="221149938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221149938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221149938">(Dec 29 2020 at 17:17)</a>:</h4>
<p>Are you cloning the entire thing?</p>



<a name="221150064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150064">(Dec 29 2020 at 17:19)</a>:</h4>
<p>Yes, I added fields with copies of the original ones. But I'm sure I'm missing something.</p>



<a name="221150094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150094">(Dec 29 2020 at 17:19)</a>:</h4>
<p>Hmm, interesting, so that's 200 MB of unaccounted memory</p>



<a name="221150103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150103">(Dec 29 2020 at 17:19)</a>:</h4>
<p>Does it contain an <code>Arc</code> or similar?</p>



<a name="221150168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150168">(Dec 29 2020 at 17:20)</a>:</h4>
<p>Shame that there's no good memory profiler, would remove a lot of the guesswork</p>



<a name="221150217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150217">(Dec 29 2020 at 17:21)</a>:</h4>
<p>I'm tempted to dump the whole thing to disk, in case something catches my eye -- if I could only figure out how to.</p>



<a name="221150735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221150735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221150735">(Dec 29 2020 at 17:27)</a>:</h4>
<p>I also think we're not calling <code>shirk_to_fit</code> on those <code>HashMap</code>s, but adding them didn't work or didn't do anything</p>



<a name="221159801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221159801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221159801">(Dec 29 2020 at 19:26)</a>:</h4>
<p>One thing that would be interesting to investigate is to skip the item tree if a macro-generated file consists only of a single macro invocation (something that happens often with self-invoking macros)</p>



<a name="221159829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221159829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221159829">(Dec 29 2020 at 19:27)</a>:</h4>
<p>I've taken some measurements a while ago that indicated that roughly half of all itemtrees come from macros. Much fewer than I expected, but it could still be worth it.</p>



<a name="221159908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221159908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221159908">(Dec 29 2020 at 19:28)</a>:</h4>
<p>That's a lot of macros</p>



<a name="221160018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221160018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221160018">(Dec 29 2020 at 19:29)</a>:</h4>
<p>Just tried the profiling thing again and neither Massif nor DHAT nor heaptrack are usable on r-a</p>



<a name="221160099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221160099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221160099">(Dec 29 2020 at 19:30)</a>:</h4>
<blockquote>
<p>[Disabling MBE] seems to speed up parsing by some 45%</p>
</blockquote>
<p>Forgot about that one <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> But that's mostly unrelated to the memory usage.</p>



<a name="221160171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221160171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221160171">(Dec 29 2020 at 19:31)</a>:</h4>
<p>I wonder if profiling would work better on some <code>no_std</code> code</p>



<a name="221161823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221161823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221161823">(Dec 29 2020 at 19:54)</a>:</h4>
<p>Maybe try nnethercote's Rusty DHAT thing?</p>



<a name="221161943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221161943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221161943">(Dec 29 2020 at 19:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="226095">Dirkjan Ochtman</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Is.20this.20correct.3F/near/221161823">said</a>:</p>
<blockquote>
<p>Maybe try nnethercote's Rusty DHAT thing?</p>
</blockquote>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/6831">https://github.com/rust-analyzer/rust-analyzer/pull/6831</a></p>



<a name="221169289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221169289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221169289">(Dec 29 2020 at 21:34)</a>:</h4>
<p>fair enough</p>



<a name="221466422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221466422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221466422">(Jan 03 2021 at 19:23)</a>:</h4>
<blockquote>
<p>22975 ItemTrees, 20519 from macro expansion, 2456 from normal files</p>
</blockquote>
<p>Oops, looks like I was grossly misremembering the numbers</p>



<a name="221466427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221466427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221466427">(Jan 03 2021 at 19:23)</a>:</h4>
<p>Maybe last time I looked at memory usage, not count</p>



<a name="221542037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221542037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221542037">(Jan 04 2021 at 16:05)</a>:</h4>
<p>oh wow</p>



<a name="221542183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221542183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221542183">(Jan 04 2021 at 16:06)</a>:</h4>
<p>Hm, I wish we could do something about expansions...</p>



<a name="221542338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221542338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221542338">(Jan 04 2021 at 16:07)</a>:</h4>
<p>Like, "there are few files" is an important optimization tool, and macros break that</p>



<a name="221769041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/221769041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#221769041">(Jan 06 2021 at 13:54)</a>:</h4>
<p>Some stats about mbe: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5549#issuecomment-755311449">https://github.com/rust-analyzer/rust-analyzer/issues/5549#issuecomment-755311449</a></p>



<a name="223119824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/223119824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#223119824">(Jan 18 2021 at 13:35)</a>:</h4>
<p>On <a href="https://github.com/nrf-rs/nrf-hal/">nrf-hal</a>, with RSS of about 1.5 GB:</p>
<div class="codehilite"><pre><span></span><code>Per-query memory usage:
   471mb ItemTreeQuery
    76mb ImplDataQuery
    52mb HygieneFrameQuery
</code></pre></div>
<p>Yesterday I saw r-a using a total of 3.5 GB, even (but the memory usage reported there was broken)</p>



<a name="223119857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/223119857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#223119857">(Jan 18 2021 at 13:35)</a>:</h4>
<p>Perhaps the most realistic way to reduce this is to start doing periodic GC again?</p>



<a name="223120158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/223120158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#223120158">(Jan 18 2021 at 13:38)</a>:</h4>
<p>Seems reasonable!</p>



<a name="223120205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/223120205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#223120205">(Jan 18 2021 at 13:38)</a>:</h4>
<p>But also ItemTree feels like it should be smaller perhaps...</p>



<a name="224013692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/224013692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#224013692">(Jan 26 2021 at 09:18)</a>:</h4>
<p>Do we ever rebuild the item tree?</p>



<a name="224015246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/224015246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#224015246">(Jan 26 2021 at 09:33)</a>:</h4>
<p>when the file itself chages</p>



<a name="224015514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/224015514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#224015514">(Jan 26 2021 at 09:36)</a>:</h4>
<p>Oh, then we don't indefinitely accumulate old items</p>



<a name="224015662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/224015662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#224015662">(Jan 26 2021 at 09:38)</a>:</h4>
<p>Might still be good to observe the counts...</p>



<a name="225201129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225201129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225201129">(Feb 04 2021 at 18:25)</a>:</h4>
<p>I've stared at DHAT logs and saw a lot of path lowering, so this reduces memory usage of <code>ItemTreeQuery</code> by ~20% <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7557">https://github.com/rust-analyzer/rust-analyzer/pull/7557</a></p>



<a name="225204036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225204036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225204036">(Feb 04 2021 at 18:46)</a>:</h4>
<p>Should we also add <code>Count</code>s to these?</p>



<a name="225205878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225205878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225205878">(Feb 04 2021 at 19:00)</a>:</h4>
<p>we could, though that would make them even larger</p>



<a name="225205975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225205975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225205975">(Feb 04 2021 at 19:01)</a>:</h4>
<p><code>Count</code> is a ZST, I think</p>



<a name="225206016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225206016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225206016">(Feb 04 2021 at 19:01)</a>:</h4>
<p><a href="https://github.com/matklad/countme/blob/master/src/lib.rs#L70">https://github.com/matklad/countme/blob/master/src/lib.rs#L70</a></p>



<a name="225206171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225206171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225206171">(Feb 04 2021 at 19:02)</a>:</h4>
<p>oh, right, it's a global hashmap</p>



<a name="225293035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293035">(Feb 05 2021 at 12:37)</a>:</h4>
<div class="codehilite"><pre><span></span><code>hir_def::item_tree::Const               12_225       12_225       12_225
hir_def::item_tree::Enum                 1_360        1_360        1_360
hir_def::item_tree::ExternCrate            804          456          455
hir_def::item_tree::Field               14_995       14_995       14_995
hir_def::item_tree::Function            64_000       64_000       64_000
hir_def::item_tree::Impl                35_714       35_714       35_714
hir_def::item_tree::Import              26_796       26_796       26_796
hir_def::item_tree::ItemTree            46_191       46_191       46_191
hir_def::item_tree::MacroCall           63_149       63_149       63_149
hir_def::item_tree::MacroDef                20           20           20
hir_def::item_tree::MacroRules           1_057        1_057        1_057
hir_def::item_tree::Mod                  3_710        3_710        3_710
hir_def::item_tree::Static                 864          864          864
hir_def::item_tree::Struct               5_252        5_252        5_252
hir_def::item_tree::Trait                  870          870          870
hir_def::item_tree::TypeAlias            7_746        7_746        7_746
hir_def::item_tree::Union                   11           11           11
hir_def::item_tree::Variant              5_666        5_666        5_666
</code></pre></div>



<a name="225293168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293168">(Feb 05 2021 at 12:39)</a>:</h4>
<p>Well, that doesn't seem too useful</p>



<a name="225293391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293391">(Feb 05 2021 at 12:41)</a>:</h4>
<p>huh?</p>



<a name="225293454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293454">(Feb 05 2021 at 12:42)</a>:</h4>
<p>I asked about adding counts to the item tree structs</p>



<a name="225293458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293458">(Feb 05 2021 at 12:42)</a>:</h4>
<p>why there are so many consts? I'd expect structs to be more frequent</p>



<a name="225293475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293475">(Feb 05 2021 at 12:42)</a>:</h4>
<p>910 in libstd</p>



<a name="225293485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293485">(Feb 05 2021 at 12:42)</a>:</h4>
<div class="codehilite"><pre><span></span><code>hir_def::item_tree::Const                  910          910          910
hir_def::item_tree::Enum                   211          211          211
hir_def::item_tree::ExternCrate             10            8            7
hir_def::item_tree::Field                1_327        1_327        1_327
hir_def::item_tree::Function            14_233       14_233       14_233
hir_def::item_tree::Impl                 9_390        9_390        9_390
hir_def::item_tree::Import               3_192        3_192        3_192
hir_def::item_tree::ItemTree             4_764        4_764        4_764
hir_def::item_tree::MacroCall            8_205        8_205        8_205
hir_def::item_tree::MacroDef                20           20           20
hir_def::item_tree::MacroRules             228          228          228
hir_def::item_tree::Mod                    606          606          606
hir_def::item_tree::Static                  66           66           66
hir_def::item_tree::Struct                 639          639          639
hir_def::item_tree::Trait                  203          203          203
hir_def::item_tree::TypeAlias            3_092        3_092        3_092
hir_def::item_tree::Union                    3            3            3
hir_def::item_tree::Variant                866          866          866
</code></pre></div>



<a name="225293534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Is%20this%20correct%3F/near/225293534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Is.20this.20correct.3F.html#225293534">(Feb 05 2021 at 12:43)</a>:</h4>
<p>Be a rebel, use a Union XD</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>